﻿using System.Data;
using System.Configuration;
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;
using System.Data.SqlClient;
using System.Drawing;
using System.Net.Mail;
using System.Text;
using System.Web.Services;





public partial class admin_NewClientRent : System.Web.UI.Page
{
    DataTable table = new DataTable("Customers");
    string p_id =null;
    string c_id;
    string t_id;
    private byte[] ConvertImageToByteArray(System.Drawing.Image imageToConvert, System.Drawing.Imaging.ImageFormat formatOfImage)
    {
        byte[] Ret;
        try
        {
            using (MemoryStream ms = new MemoryStream())
            {
                imageToConvert.Save(ms, formatOfImage);
                Ret = ms.ToArray();
            }
        }
        catch (Exception) { throw; }
        return Ret;
    }
    protected void Page_Load(object sender, EventArgs e)
    {
      
       

            if (Session["p_id"] == null)
            {
                var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
                var random = new Random();
                var p_id = new string(
                    Enumerable.Repeat(chars, 8)
                              .Select(s => s[random.Next(s.Length)])
                              .ToArray());
              



                //Session["p_id"] = p_id;
                SqlConnection con = null;

                con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString);
                con.Open();


                SqlCommand cmd1 = new SqlCommand("SELECT c_id FROM property_rent where c_id='" + p_id + "'", con);

                SqlDataReader dr2 = cmd1.ExecuteReader();


                if (dr2.Read())
                {
                    var chars1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
                    var random1 = new Random();
                    var n_id = new string(
                        Enumerable.Repeat(chars1, 8 )
                                  .Select(s => s[random1.Next(s.Length)])
                                  .ToArray());


                    Request.QueryString["p_id"] = n_id;

                }






                else
                {
                    Session["p_id"] = p_id;

                }
                dr2.Close();
                con.Close();





            }

            else
            {
                p_id = Session["p_id"].ToString();
            }











            if (Session["t_id"] == null)
            {
                var chars2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
                var random2 = new Random();
                var t_id = new string(
                    Enumerable.Repeat(chars2, 8)
                              .Select(s => s[random2.Next(s.Length)])
                              .ToArray());
              
                Session["t_id"] = t_id;
            }

            else
            {
                t_id = Session["t_id"].ToString();
            }
            //Session["myTable"] = table;
            if (!IsPostBack)
            {
                table.Columns.Add("action_");
                table.Columns.Add("p_id");
                table.Columns.Add("t_id");
                table.Columns.Add("deal_status");
                table.Columns.Add("created");
                table.Columns.Add("update_");
                table.Columns.Add("min_");
                table.Columns.Add("hrs");
                table.Columns.Add("fast_reminder");
                table.Columns.Add("day_");
                table.Columns.Add("hr");
                table.Columns.Add("min1");
                table.Columns.Add("agent");
                table.Columns.Add("sec_agent");
                table.Columns.Add("rank");
                table.Columns.Add("cust_rank");
                table.Columns.Add("commission");
                table.Columns.Add("sig");
                table.Columns.Add("refer");
                table.Columns.Add("cust_refer");
                table.Columns.Add("comment");
                table.Columns.Add("terms");
                table.Columns.Add("to_do");
                table.Columns.Add("cus_to_do");
                table.Columns.Add("status_");
                table.Columns.Add("full_day");
                table.Columns.Add("to_do_msg");
                table.Columns.Add("to_do_date");
                table.Columns.Add("to_hr");
                table.Columns.Add("to_min");
                table.Columns.Add("added_by");
                table.Columns.Add("cus_deal_status");
                table.Columns.Add("cust_stat");
                table.Columns.Add("cust_reminder");

            }


            if (Session["myTable"] == null)
            {
                Session["myTable"] = table;
            }

            else
            {


                table = Session["myTable"] as DataTable;

            }


            table = Session["myTable"] as DataTable;


            //TextBox16.Text = "0";

            if (Session["email"] == null)
            {
                Session["email"] = "admin";
            }
            // Label1.Text = Session["email"].ToString();
            // txtcreate.Text = System.DateTime.Now.ToString();
            txtagent.Text = Session["email"].ToString();



     
    }
    protected void DropDownList5_SelectedIndexChanged(object sender, System.EventArgs e)
    {
        //Session["type"] = DropDownList5.SelectedValue;
        //Session["proptype"] = DropDownList6.SelectedValue;


    }

    protected void ok(object sender, System.EventArgs e)
    {


        if (Session["t_id"] == null)
        {
            //Random r1 = new Random();
            //int num = r1.Next(0, 99999999); // generate random number
            //string number = string.Format("{0:D8}", num);

            //Random r2 = new Random();
            //int num2 = r2.Next(0, 26); // generate random letter
            //char letter = (char)('A' + num2);

            var chars3 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
            var random3 = new Random();
            var t_id = new string(
                Enumerable.Repeat(chars3, 8)
                          .Select(s => s[random3.Next(s.Length)])
                          .ToArray());
            //t_id = letter + number;
            Session["t_id"] = t_id;
        }

        else
        {
            t_id = Session["t_id"].ToString();
        }
        try
        {

            table.Rows.Add(p_id, p_id, t_id, DropDownList4.SelectedValue, txtdate.Text, txtupdate.Text, ddlhr.SelectedValue, ddlmint.SelectedValue, DropDownList57.SelectedValue, txtFR.Text, ddlhr0.SelectedValue, ddlmint0.SelectedValue, txtagent.Text, DropDownList6.SelectedValue, DropDownList54.SelectedValue, TextBox58.Text, txtcommsin.Text, DropDownList55.SelectedValue, DropDownList56.SelectedValue, TextBox59.Text, txtcomment.Text, txtterms.Text, DropDownList28.SelectedValue, TextBox61.Text, DropDownList29.SelectedValue, DropDownList30.SelectedValue, txtmsg.Text, txttododate.Text, ddlhr1.SelectedValue, ddlmint1.SelectedValue, "Admin", TextBox56.Text, TextBox78.Text, TextBox57.Text);

        }

        catch (Exception err)
        {
            Label2.Text=err.Message;

        }


        GridView1.DataSource = table;
        GridView1.DataBind();
        Session["myTable"] = table;

        string path1 = Server.MapPath("upload/" + Session["p_id"] + "/" + "Doc");
        if (!Directory.Exists(path1))
        {
            Directory.CreateDirectory(path1);
        }

        if (FileUpload1.HasFile)
        {

            HttpFileCollection hfc = Request.Files;
            for (int i = 0; i < hfc.Count; i++)
            {

                HttpPostedFile hpf = hfc[i];
                if (hpf.ContentLength > 0)
                {
                    hpf.SaveAs(Server.MapPath("upload/" + Session["p_id"] + "/" + "Doc/" + System.IO.Path.GetFileName(hpf.FileName)));

                    SqlConnection co = null;
                    co = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString);
                    co.Open();

                    SqlCommand cmd = new SqlCommand("Insert into files values(@id,@FileName ,@FilePath )", co);
                    //id nvarchar (50),
                    //FileName nvarchar (50),
                    //FilePath nvarchar (50)


                    cmd.Parameters.AddWithValue("@id", Session["p_id"]);
                    cmd.Parameters.AddWithValue("@FileName", System.IO.Path.GetFileName(hpf.FileName));
                    cmd.Parameters.AddWithValue("@FilePath", ("upload/" + Session["p_id"] + "/" + "Doc/" + hpf.FileName));


                    cmd.ExecuteNonQuery();
                    co.Close();


                }
            }
        }

        DropDownList4.SelectedIndex = 0;

        DropDownList8.SelectedIndex = 0;
        txtdate.Text = "";
        txtupdate.Text = "";
        ddlhr.SelectedIndex = 0;
        ddlmint1.SelectedIndex = 0;
        DropDownList57.SelectedIndex = 0;
        txtFR.Text = "";
        ddlhr0.SelectedIndex = 0;
        ddlmint0.SelectedIndex = 0;
        DropDownList54.SelectedIndex = 0;
        txtcommsin.Text = "";
        DropDownList54.SelectedIndex = 0;
        DropDownList55.SelectedIndex = 0;
        TextBox56.Text = "";
        txtcomment.Text = "";
        txtterms.Text = "";
        DropDownList28.SelectedIndex = 0;

        DropDownList29.SelectedIndex = 0;
        DropDownList30.SelectedIndex = 0;
        txtmsg.Text = "";
        txttododate.Text = "";
        ddlhr1.SelectedIndex = 0;
        ddlmint1.SelectedIndex = 0;
        ddlmint.SelectedIndex = 0;
        DropDownList56.SelectedIndex = 0;
        DropDownList6.SelectedIndex = 0;



    }


    public void properties()
    {
        string cat = null;
        cat = DropDownList1.SelectedValue;
        SqlConnection conn = null;
        conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString);
        conn.Open();





        var chars4 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        var random4 = new Random();
       c_id = new string(
            Enumerable.Repeat(chars4, 8)
                      .Select(s => s[random4.Next(s.Length)])
                      .ToArray());


        //Random r1 = new Random();
        //int num = r1.Next(0, 99999999); // generate random number
        //string number = string.Format("{0:D8}", num);

        //Random r2 = new Random();
        //int num2 = r2.Next(0, 26); // generate random letter
        //char letter = (char)('A' + num2);


        //c_id = letter + number; // join both as ID 


        SqlCommand cmd = new SqlCommand("Insert into property_rent values(@c_id,@type,@c_type,@custom_ctype, @agent_name,@property,@fname,@lname,@email_id, @phone, @h_no, @street, @nghr, @state1, @zip, @country, @city, @street1, @nghr1, @state1, @country1, @zip1, @f_room, @f_floor, @to,  @balconies, @balconies_value,  @balconies_size,  @balconies0, @balconies_value1, @balconies_size1,@g_floor,@cust_gfloor, @to_room, @storage, @ac, @custom_ac,@saferoom, @cust_saferoom, @no_of_resident, @budget, @type_budget, @p_size,@p_size_sign, @furniture, @cust_furn, @entering_date, @roommate, @n_of_roommate, @guarantee, @cust_guarantee,@elevator,@cust_elevator, @voucher,  @cust_voucher, @prop_cond, @cust_prop_cond,@animals, @cust_animals,  @smokers, @cust_smoker, @occupation, @a_hrs, @parking, @custparking, @north, @p_south,  @p_east,  @p_west, @smart_house,  @alarm , @bars, @handicap,@guard,  @gym,  @jacuzie, @pool,  @check_custom,  @custom,@comments,@status1,  @adding_date,  @adding_by, @cust_pro_typle, @cust_storage, @house_no)", conn);
        cmd.Parameters.AddWithValue("@c_id", Session["p_id"]);
        cmd.Parameters.AddWithValue("@type", "Want to Rent");
        cmd.Parameters.AddWithValue("@c_type", DropDownList52.SelectedValue);
        cmd.Parameters.AddWithValue("@custom_ctype", TextBox55.Text);
        cmd.Parameters.AddWithValue("@agent_name", DropDownList15.SelectedValue);
        cmd.Parameters.AddWithValue("@property", DropDownList31.SelectedValue);


        cmd.Parameters.AddWithValue("@fname", TextBox50.Text);
        cmd.Parameters.AddWithValue("@lname", txtlname1.Text);

        cmd.Parameters.AddWithValue("@email_id", TextBox22.Text);
        cmd.Parameters.AddWithValue("@phone", TextBox21.Text);
        cmd.Parameters.AddWithValue("@h_no", TextBox18.Text);
        cmd.Parameters.AddWithValue("@street", TextBox19.Text);
        cmd.Parameters.AddWithValue("@nghr", TextBox23.Text);
        cmd.Parameters.AddWithValue("@zip", TextBox20.Text);
        cmd.Parameters.AddWithValue("@country", TextBox24.Text);
        cmd.Parameters.AddWithValue("@city", TextBox25.Text);
        cmd.Parameters.AddWithValue("@street1", TextBox26.Text);
        cmd.Parameters.AddWithValue("@nghr1", TextBox27.Text);
        cmd.Parameters.AddWithValue("@state1", TextBox36.Text);
        cmd.Parameters.AddWithValue("@country1", TextBox29.Text);
        cmd.Parameters.AddWithValue("@zip1", TextBox37.Text);
        cmd.Parameters.AddWithValue("@f_room", TextBox3.Text);

        cmd.Parameters.AddWithValue("@f_floor", TextBox4.Text);
        cmd.Parameters.AddWithValue("@to", TextBox30.Text);
        cmd.Parameters.AddWithValue("@balconies", txtBalconies.Text);
        cmd.Parameters.AddWithValue("@balconies_value", TextBox6.Text);
        cmd.Parameters.AddWithValue("@balconies_size", DropDownList46.SelectedValue);

        cmd.Parameters.AddWithValue("@balconies0", txtBalconies0.Text);
        cmd.Parameters.AddWithValue("@balconies_value1", TextBox48.Text);

        cmd.Parameters.AddWithValue("@balconies_size1", DropDownList47.SelectedValue);
        cmd.Parameters.AddWithValue("@g_floor", DropDownList50.SelectedValue);
        cmd.Parameters.AddWithValue("@cust_gfloor", TextBox52.Text);
        cmd.Parameters.AddWithValue("@to_room", TextBox34.Text);

        cmd.Parameters.AddWithValue("@storage", DropDownList48.SelectedValue);
        cmd.Parameters.AddWithValue("@ac", DropDownList16.SelectedValue);

        cmd.Parameters.AddWithValue("@custom_ac", TextBox33.Text);

        cmd.Parameters.AddWithValue("@saferoom", DropDownList32.SelectedValue);

        cmd.Parameters.AddWithValue("@cust_saferoom", TextBox38.Text);
        cmd.Parameters.AddWithValue("@no_of_resident", TextBox31.Text);
        cmd.Parameters.AddWithValue("@budget", TextBox9.Text);
        cmd.Parameters.AddWithValue("@type_budget", DropDownList33.SelectedValue);
        cmd.Parameters.AddWithValue("@p_size", DropDownList7.SelectedValue);
        cmd.Parameters.AddWithValue("@p_size_sign", TextBox53.Text);
        cmd.Parameters.AddWithValue("@furniture", DropDownList18.SelectedValue);


        cmd.Parameters.AddWithValue("@cust_furn", TextBox39.Text);
        cmd.Parameters.AddWithValue("@entering_date", TextBox12.Text);
        cmd.Parameters.AddWithValue("@roommate", TextBox46.Text);

        cmd.Parameters.AddWithValue("@n_of_roommate", TextBox14.Text);
        cmd.Parameters.AddWithValue("@guarantee", DropDownList10.SelectedValue);
        cmd.Parameters.AddWithValue("@cust_guarantee", TextBox40.Text);
        cmd.Parameters.AddWithValue("@elevator", DropDownList49.SelectedValue);
        cmd.Parameters.AddWithValue("@cust_elevator", TextBox51.Text);
        cmd.Parameters.AddWithValue("@voucher", DropDownList9.SelectedValue);
        cmd.Parameters.AddWithValue("@cust_voucher", TextBox41.Text);
        cmd.Parameters.AddWithValue("@prop_cond", DropDownList13.SelectedValue);
        cmd.Parameters.AddWithValue("@cust_prop_cond", TextBox42.Text);
        cmd.Parameters.AddWithValue("@animals", DropDownList12.SelectedValue);
        cmd.Parameters.AddWithValue("@cust_animals", TextBox43.Text);
        cmd.Parameters.AddWithValue("@smokers", DropDownList11.Text);

        cmd.Parameters.AddWithValue("@cust_smoker", TextBox44.Text);
        cmd.Parameters.AddWithValue("@occupation", TextBox32.Text);
        cmd.Parameters.AddWithValue("@a_hrs", TextBox60.Text);

        cmd.Parameters.AddWithValue("@parking", TextBox7.Text);
        cmd.Parameters.AddWithValue("@custparking", TextBox45.Text);


        cmd.Parameters.AddWithValue("@north", CheckBox9.Checked);
        cmd.Parameters.AddWithValue("@p_south", CheckBox10.Checked);
        cmd.Parameters.AddWithValue("@p_east", CheckBox11.Checked);
        cmd.Parameters.AddWithValue("@p_west", CheckBox12.Checked);
        cmd.Parameters.AddWithValue("@smart_house", CheckBox1.Checked);
        cmd.Parameters.AddWithValue("@alarm ", CheckBox2.Checked);
        cmd.Parameters.AddWithValue("@bars", CheckBox3.Checked);
        cmd.Parameters.AddWithValue("@handicap", CheckBox4.Checked);
        cmd.Parameters.AddWithValue("@guard", CheckBox5.Checked);
        cmd.Parameters.AddWithValue("@gym", CheckBox6.Checked);
        cmd.Parameters.AddWithValue("@jacuzie", CheckBox7.Checked);
        cmd.Parameters.AddWithValue("@pool", CheckBox8.Checked);
        cmd.Parameters.AddWithValue("@check_custom", CheckBox13.Checked);
        cmd.Parameters.AddWithValue("@custom", TextBox5.Text);

        cmd.Parameters.AddWithValue("@comments", TextBox13.Text);

        cmd.Parameters.AddWithValue("@status1", "1");
        cmd.Parameters.AddWithValue("@adding_date", System.DateTime.Now);
        cmd.Parameters.AddWithValue("@adding_by", Session["email"].ToString());
        cmd.Parameters.AddWithValue("@cust_pro_typle", TextBox28.Text);
        cmd.Parameters.AddWithValue("@cust_storage", TextBox15.Text);
		cmd.Parameters.AddWithValue("@house_no", TextBox17.Text);
        cmd.ExecuteNonQuery();
        conn.Close();

    }


    public void task()
    {
        SqlConnection conn = null;
        conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString);
        conn.Open();

        SqlCommand cmd3 = new SqlCommand("insert into task (action_,p_id,t_id,deal_status,created,update_,hrs,min_,fast_reminder,day_,hr,min1,agent,sec_agent,rank,cust_rank,commission,sig,refer,cust_refer,comment,terms,to_do,cus_to_do,status_,full_day,to_do_msg,to_do_date,to_hr,to_min,added_by,cus_deal_status,cust_stat,cust_reminder) values  (@action_,@p_id ,@t_id ,@deal_status ,@created ,@update_ ,@min_ ,@hrs ,@fast_reminder ,@day_ ,@hr ,@min1 ,@agent ,@sec_agent ,@rank ,@cust_rank ,@commission ,@sig ,@refer ,@cust_refer ,@comment ,@terms ,@to_do ,@cus_to_do ,@status_ ,@full_day ,@to_do_msg ,@to_do_date ,@to_hr ,@to_min,@added_by,@cus_deal_status,@cust_stat,@cust_reminder)", conn);
        cmd3.Parameters.AddWithValue("@action_", "p_id");
        cmd3.Parameters.AddWithValue("@p_id ", Session["p_id"]);
        cmd3.Parameters.AddWithValue("@t_id ", Session["t_id"]);
        cmd3.Parameters.AddWithValue("@deal_status ", DropDownList4.SelectedValue);
        cmd3.Parameters.AddWithValue("@created ", txtdate.Text);
        cmd3.Parameters.AddWithValue("@update_ ", txtupdate.Text);
        cmd3.Parameters.AddWithValue("@hrs", ddlhr.SelectedValue);
        cmd3.Parameters.AddWithValue("@min_", ddlmint.SelectedValue);

        cmd3.Parameters.AddWithValue("@fast_reminder", DropDownList57.SelectedValue);
        cmd3.Parameters.AddWithValue("@day_ ", txtFR.Text);
        cmd3.Parameters.AddWithValue("@hr", ddlhr0.SelectedValue);
        cmd3.Parameters.AddWithValue("@min1", ddlmint0.SelectedValue);
        cmd3.Parameters.AddWithValue("@agent", txtagent.Text);
        cmd3.Parameters.AddWithValue("@sec_agent", DropDownList6.SelectedValue);
        cmd3.Parameters.AddWithValue("@rank", DropDownList54.SelectedValue);
        cmd3.Parameters.AddWithValue("@cust_rank", TextBox58.Text);
        cmd3.Parameters.AddWithValue("@commission", txtcommsin.Text);
        cmd3.Parameters.AddWithValue("@sig", DropDownList55.SelectedValue);
        cmd3.Parameters.AddWithValue("@refer", DropDownList56.SelectedValue);
        cmd3.Parameters.AddWithValue("@cust_refer", TextBox59.Text);
        cmd3.Parameters.AddWithValue("@comment", txtcomment.Text);
        cmd3.Parameters.AddWithValue("@terms", txtterms.Text);
        cmd3.Parameters.AddWithValue("@to_do", DropDownList28.SelectedValue);
        cmd3.Parameters.AddWithValue("@cus_to_do", TextBox61.Text);
        cmd3.Parameters.AddWithValue("@status_ ", DropDownList29.SelectedValue);
        cmd3.Parameters.AddWithValue("@full_day", DropDownList30.SelectedValue);
        cmd3.Parameters.AddWithValue("@to_do_msg", txtmsg.Text);
        cmd3.Parameters.AddWithValue("@to_do_date", txttododate.Text);
        cmd3.Parameters.AddWithValue("@to_hr", ddlhr1.SelectedValue);
        cmd3.Parameters.AddWithValue("@to_min", ddlmint1.Text);

        cmd3.Parameters.AddWithValue("added_by", Session["email"]);
        cmd3.Parameters.AddWithValue("@cus_deal_status", TextBox56.Text);
        cmd3.Parameters.AddWithValue("@cust_stat", TextBox78.Text);
        cmd3.Parameters.AddWithValue("@cust_reminder", TextBox57.Text);
		
        cmd3.ExecuteNonQuery();

        conn.Close();
    }







    public void fileupload2()
    {

        if (FileUpload1.HasFile)
        {

            string path1 = Server.MapPath("upload/" + Session["p_id"] + "/" + "Doc");
            if (!Directory.Exists(path1))
            {
                Directory.CreateDirectory(path1);
                HttpFileCollection hfd = Request.Files;
                for (int i = 0; i < hfd.Count; i++)
                {
                    HttpPostedFile hf = hfd[i];
                    if (hf.ContentLength > 0)
                    {
                        hf.SaveAs(Server.MapPath("upload/" + Session["p_id"] + "/" + "Doc/" + System.IO.Path.GetFileName(hf.FileName)));

                        SqlConnection co = null;
                        co = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString);
                        co.Open();

                        SqlCommand cmd2 = new SqlCommand("Insert into files values(@id,@FileName ,@FilePath )", co);



                        cmd2.Parameters.AddWithValue("@id", Session["p_id"]);
                        cmd2.Parameters.AddWithValue("@FileName", System.IO.Path.GetFileName(hf.FileName));
                        cmd2.Parameters.AddWithValue("@FilePath", ("upload/" + Session["p_id"] + "/" + "Doc/" + hf.FileName));


                        cmd2.ExecuteNonQuery();
                        co.Close();
                    }
                }
            }
        }


    }
    protected void Save_Click(object sender, System.EventArgs e)
    {






        if (table.Rows.Count < 1)
        {
            properties();


            fileupload2();

            task();

        }
        else
        {
            properties();


            fileupload2();

            for (int i = 0; i < table.Rows.Count; i++)
            {
                string pid = table.Rows[i]["p_id"].ToString().Trim();
                string tid = table.Rows[i]["t_id"].ToString().Trim();
                string deal_status = table.Rows[i]["deal_status"].ToString().Trim();
                string created = table.Rows[i]["created"].ToString().Trim();
                string update_ = table.Rows[i]["update_"].ToString().Trim();
                string min_ = table.Rows[i]["min_"].ToString().Trim();
                string hrs = table.Rows[i]["hrs"].ToString().Trim();
                string fast_reminder = table.Rows[i]["fast_reminder"].ToString().Trim();
                string day_ = table.Rows[i]["day_"].ToString().Trim();
                string hr = table.Rows[i]["hr"].ToString().Trim();
                string min1 = table.Rows[i]["min1"].ToString().Trim();
                string agent = table.Rows[i]["agent"].ToString().Trim();
                string sec_agent = table.Rows[i]["sec_agent"].ToString().Trim();
                string rank = table.Rows[i]["rank"].ToString().Trim();
                string cust_rank = table.Rows[i]["cust_rank"].ToString().Trim();
                string commission = table.Rows[i]["commission"].ToString().Trim();
                string sig = table.Rows[i]["sig"].ToString().Trim();
                string refer = table.Rows[i]["refer"].ToString().Trim();
                string cust_refer = table.Rows[i]["cust_refer"].ToString().Trim();
                string comment = table.Rows[i]["comment"].ToString().Trim();
                string terms = table.Rows[i]["terms"].ToString().Trim();
                string to_do = table.Rows[i]["to_do"].ToString().Trim();
                string cus_to_do = table.Rows[i]["cus_to_do"].ToString().Trim();
                string status_ = table.Rows[i]["status_"].ToString().Trim();
                string full_day = table.Rows[i]["full_day"].ToString().Trim();
                string to_do_msg = table.Rows[i]["to_do_msg"].ToString().Trim();
                string to_do_date = table.Rows[i]["to_do_date"].ToString().Trim();
                string to_hr = table.Rows[i]["to_hr"].ToString().Trim();
                string to_min = table.Rows[i]["to_min"].ToString().Trim();
                string cus_deal_status = table.Rows[i]["cus_deal_status"].ToString().Trim();

                string cust_stat = table.Rows[i]["cust_stat"].ToString().Trim();
                string cust_reminder = table.Rows[i]["cust_reminder"].ToString().Trim();

                SqlConnection conn = null;
                conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString);
                conn.Open();

                SqlCommand cmd1 = new SqlCommand("insert into task (p_id,t_id,deal_status,created,update_,min_,hrs,fast_reminder,day_,hr,min1,agent,sec_agent,rank,cust_rank,commission,sig,refer,cust_refer,comment,terms,to_do,cus_to_do,status_,full_day,to_do_msg,to_do_date,to_hr,to_min,added_by,cus_deal_status,cust_stat,cust_reminder) values  (@p_id ,@t_id ,@deal_status ,@created ,@update_ ,@min_ ,@hrs ,@fast_reminder ,@day_ ,@hr ,@min1 ,@agent ,@sec_agent ,@rank ,@cust_rank ,@commission ,@sig ,@refer ,@cust_refer ,@comment ,@terms ,@to_do ,@cus_to_do ,@status_ ,@full_day ,@to_do_msg ,@to_do_date ,@to_hr ,@to_min,@added_by,@cus_deal_status,@cust_stat,@cust_reminder)", conn);
                cmd1.Parameters.AddWithValue("@p_id ", pid);
                cmd1.Parameters.AddWithValue("@t_id ", tid);
                cmd1.Parameters.AddWithValue("@deal_status ", deal_status);
                cmd1.Parameters.AddWithValue("@created ", created);
                cmd1.Parameters.AddWithValue("@update_ ", update_);
                cmd1.Parameters.AddWithValue("@min_", min_);
                cmd1.Parameters.AddWithValue("@hrs", hrs);
                cmd1.Parameters.AddWithValue("@fast_reminder", fast_reminder);
                cmd1.Parameters.AddWithValue("@day_ ", day_);
                cmd1.Parameters.AddWithValue("@hr", hr);
                cmd1.Parameters.AddWithValue("@min1", min1);
                cmd1.Parameters.AddWithValue("@agent", agent);
                cmd1.Parameters.AddWithValue("@sec_agent", sec_agent);
                cmd1.Parameters.AddWithValue("@rank", rank);
                cmd1.Parameters.AddWithValue("@cust_rank", cust_rank);
                cmd1.Parameters.AddWithValue("@commission", commission);
                cmd1.Parameters.AddWithValue("@sig", sig);
                cmd1.Parameters.AddWithValue("@refer", refer);
                cmd1.Parameters.AddWithValue("@cust_refer", cust_refer);
                cmd1.Parameters.AddWithValue("@comment", comment);
                cmd1.Parameters.AddWithValue("@terms", terms);
                cmd1.Parameters.AddWithValue("@to_do", to_do);
                cmd1.Parameters.AddWithValue("@cus_to_do", cus_to_do);
                cmd1.Parameters.AddWithValue("@status_ ", status_);
                cmd1.Parameters.AddWithValue("@full_day", full_day);
                cmd1.Parameters.AddWithValue("@to_do_msg", to_do_msg);
                cmd1.Parameters.AddWithValue("@to_do_date", to_do_date);
                cmd1.Parameters.AddWithValue("@to_hr", to_hr);
                cmd1.Parameters.AddWithValue("@to_min", to_min);
                cmd1.Parameters.AddWithValue("@added_by", Session["email"]);
                cmd1.Parameters.AddWithValue("@cus_deal_status", cus_deal_status);
                cmd1.Parameters.AddWithValue("@cust_stat", cust_stat);
                cmd1.Parameters.AddWithValue("@cust_reminder", cust_reminder);
                cmd1.ExecuteNonQuery();
                GridView1.Columns.Clear();

                table.Clear();

                conn.Close();
            }
















        }

        Session.Clear();
        Session.Contents.RemoveAll();

        GridView1.Columns.Clear();

        table.Clear();

        Response.Redirect("add_confirmation.aspx");

    }



    protected void txtcreate_TextChanged(object sender, EventArgs e)
    {

    }
    protected void LinkButton1_Click(object sender, System.EventArgs e)
    {
        Session.Clear();
        Session.Contents.RemoveAll();
        Response.Redirect("admin.aspx");
    }
}







